package com.ww.springboot.mybatis.controller;

//import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.api.R;
import com.ww.springboot.mybatis.data.entity.TypeTest;
import com.ww.springboot.mybatis.po.OnlineChannelServiceBindPO;
import com.ww.springboot.mybatis.service.ITypeTestService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.sql.DataSource;
import java.sql.Wrapper;
import java.util.Date;
import java.util.List;

/**
 * 描述：
 *
 * @author wanwei
 * @since 2021-07-12 16:52
 */
@RestController
@AllArgsConstructor
@RequestMapping("/typeTest")
public class TypeTestController {

    private final ITypeTestService typeTestService;

    private final DataSource dataSource;


    /**
     * 详情
     */
    @GetMapping("/add")
    public R<String> detail(@RequestParam("s") String s, @RequestParam("l") Long l) {
        TypeTest typeTest = new TypeTest();
        typeTest.setSTest(s);
        typeTest.setLTest(l);
        typeTest.setTimeTest(new Date());
        typeTestService.save(typeTest);
        return R.ok("成功");
    }

    /**
     * 详情
     */
    @GetMapping("/find")
    public R<List<TypeTest>> find(@RequestParam("s") String s, @RequestParam("l") Long l) {

        // DynamicDataSourceContextHolder.push("slave");

        TypeTest typeTest = new TypeTest();
        typeTest.setSTest(s);
        typeTest.setLTest(l);
        //typeTest.setTimeTest(new Date());
        //return R.ok(null);
//        List<TypeTest> typeTests = typeTestService.lambdaQuery()
//                .eq(TypeTest::getSTest,typeTest.getSTest())
//                .eq(TypeTest::getTimeTest,typeTest.getTimeTest())
//                .list();
        LambdaQueryWrapper<TypeTest> queryWrapper = Wrappers.<TypeTest>query().lambda();
        queryWrapper.setEntity(typeTest);
        List<TypeTest> typeTests = typeTestService.list(queryWrapper);
        return R.ok(typeTests);
    }
}
